/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package BoardGameToTreeIntegration.Rules.impl;

import BoardGame.Board;
import BoardGame.BoardGameFactory;
import BoardGame.Field;

import BoardGameToTreeIntegration.BoardGameToTreeIntegrationFactory;
import BoardGameToTreeIntegration.BoardToNode;
import BoardGameToTreeIntegration.BoardToFile;
import BoardGameToTreeIntegration.FieldToNode;

import BoardGameToTreeIntegration.Rules.FieldRule;
import BoardGameToTreeIntegration.Rules.RulesPackage;

import MocaTree.File;
import MocaTree.MocaTreeFactory;
import MocaTree.Node;

import TGGLanguage.csp.*;

import TGGRuntime.Edge;
import TGGRuntime.IsAppropriateRuleResult;
import TGGRuntime.Match;
import TGGRuntime.PerformRuleResult;
import TGGRuntime.TGGRuntimeFactory;

import TGGRuntime.impl.AbstractRuleImpl;

import csp.constraints.*;

import de.upb.tools.sdm.*;

import java.lang.reflect.InvocationTargetException;

import java.util.*;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Field Rule</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * </p>
 *
 * @generated
 */
public class FieldRuleImpl extends AbstractRuleImpl implements FieldRule {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected FieldRuleImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return RulesPackage.Literals.FIELD_RULE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PerformRuleResult perform_FWD_Field_0(Field row) {
		boolean fujaba__Success = false;
		PerformRuleResult ruleResult = null;
		FieldToNode f2n = null;
		Node rowNode = null;
		Node field = null;
		Edge f2n__source__row = null;
		Edge f2n__target__field = null;
		Edge field__children__rowNode = null;
		Edge root__children__rowNode = null;
		Edge row__board__board = null;
		Node root = null;
		Iterator fujaba__IterBoardToB2n = null;
		BoardToNode b2n = null;
		Board board = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE.createPerformRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern find context
		try {
			fujaba__Success = false;

			// check object row is really bound
			JavaSDM.ensure(row != null);
			// bind object
			board = row.getBoard();

			// check object board is really bound
			JavaSDM.ensure(board != null);

			// iterate to-many link source from board to b2n
			fujaba__Success = false;

			fujaba__IterBoardToB2n = new ArrayList(
					org.moflon.util.eMoflonEMFUtil.getOppositeReference(board,
							BoardToNode.class, "source")).iterator();

			while (fujaba__IterBoardToB2n.hasNext()) {
				try {
					b2n = (BoardToNode) fujaba__IterBoardToB2n.next();

					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// bind object
					root = b2n.getTarget();

					// check object root is really bound
					JavaSDM.ensure(root != null);

					// Create CSP
					CSP csp = CspFactory.eINSTANCE.createCSP();

					// Create literals
					Variable<Integer> literal0 = CspFactory.eINSTANCE
							.createVariable("literal0", true, csp);
					literal0.setValue(0);

					// Create implicit parameters
					Variable<Integer> var_row_y = CspFactory.eINSTANCE
							.createVariable("row.y", true, csp);
					var_row_y.setValue(row.getY());
					Variable<Integer> var_row_x = CspFactory.eINSTANCE
							.createVariable("row.x", true, csp);
					var_row_x.setValue(row.getX());

					// Create explicit parameters

					// Create unbound variables
					Variable<Integer> var_rowNode_index = CspFactory.eINSTANCE
							.createVariable("rowNode.index", csp);
					Variable<Integer> var_field_index = CspFactory.eINSTANCE
							.createVariable("field.index", csp);

					// Create constraints
					Eq<Integer> eq = new Eq<Integer>();
					Eq<Integer> eq_0 = new Eq<Integer>();
					Eq<Integer> eq_1 = new Eq<Integer>();

					csp.getConstraints().add(eq);
					csp.getConstraints().add(eq_0);
					csp.getConstraints().add(eq_1);

					// Solve CSP
					eq.solve(var_row_x, literal0);
					eq_0.solve(var_row_y, var_rowNode_index);
					eq_1.solve(var_row_x, var_field_index);

					fujaba__Success = csp.check();
					if (fujaba__Success) {
						// story pattern perform transformation
						try {
							fujaba__Success = false;

							// check object b2n is really bound
							JavaSDM.ensure(b2n != null);
							// check object board is really bound
							JavaSDM.ensure(board != null);
							// check object root is really bound
							JavaSDM.ensure(root != null);
							// check object row is really bound
							JavaSDM.ensure(row != null);
							// check link fields from row to board
							JavaSDM.ensure(board.equals(row.getBoard()));

							// check link source from b2n to board
							JavaSDM.ensure(board.equals(b2n.getSource()));

							// check link target from b2n to root
							JavaSDM.ensure(root.equals(b2n.getTarget()));

							// create object f2n
							f2n = BoardGameToTreeIntegrationFactory.eINSTANCE
									.createFieldToNode();
							// create object rowNode
							rowNode = MocaTreeFactory.eINSTANCE.createNode();
							// create object field
							field = MocaTreeFactory.eINSTANCE.createNode();
							// assign attribute rowNode
							rowNode.setIndex(var_rowNode_index.getValue());
							// assign attribute field
							field.setIndex(var_field_index.getValue());
							// create link
							f2n.setSource(row);

							// create link
							field.getChildren().add(rowNode);

							// create link
							root.getChildren().add(rowNode);

							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(f2n, field, "target");
							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						// story pattern collect translated elements
						try {
							fujaba__Success = false;

							// check object f2n is really bound
							JavaSDM.ensure(f2n != null);
							// check object field is really bound
							JavaSDM.ensure(field != null);
							// check object row is really bound
							JavaSDM.ensure(row != null);
							// check object rowNode is really bound
							JavaSDM.ensure(rowNode != null);
							// check object ruleResult is really bound
							JavaSDM.ensure(ruleResult != null);
							// check isomorphic binding between objects rowNode and field
							JavaSDM.ensure(!rowNode.equals(field));

							// assign attribute ruleResult
							ruleResult.setSuccess(true);
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, field,
											"createdElements");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, rowNode,
											"createdElements");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, row,
											"translatedElements");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, f2n,
											"createdLinkElements");
							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						// story pattern bookkeeping for edges
						try {
							fujaba__Success = false;

							// check object b2n is really bound
							JavaSDM.ensure(b2n != null);
							// check object board is really bound
							JavaSDM.ensure(board != null);
							// check object f2n is really bound
							JavaSDM.ensure(f2n != null);
							// check object field is really bound
							JavaSDM.ensure(field != null);
							// check object root is really bound
							JavaSDM.ensure(root != null);
							// check object row is really bound
							JavaSDM.ensure(row != null);
							// check object rowNode is really bound
							JavaSDM.ensure(rowNode != null);
							// check object ruleResult is really bound
							JavaSDM.ensure(ruleResult != null);
							// check isomorphic binding between objects board and b2n
							JavaSDM.ensure(!board.equals(b2n));

							// check isomorphic binding between objects f2n and b2n
							JavaSDM.ensure(!f2n.equals(b2n));

							// check isomorphic binding between objects field and b2n
							JavaSDM.ensure(!field.equals(b2n));

							// check isomorphic binding between objects root and b2n
							JavaSDM.ensure(!root.equals(b2n));

							// check isomorphic binding between objects row and b2n
							JavaSDM.ensure(!row.equals(b2n));

							// check isomorphic binding between objects rowNode and b2n
							JavaSDM.ensure(!rowNode.equals(b2n));

							// check isomorphic binding between objects f2n and board
							JavaSDM.ensure(!f2n.equals(board));

							// check isomorphic binding between objects field and board
							JavaSDM.ensure(!field.equals(board));

							// check isomorphic binding between objects root and board
							JavaSDM.ensure(!root.equals(board));

							// check isomorphic binding between objects row and board
							JavaSDM.ensure(!row.equals(board));

							// check isomorphic binding between objects rowNode and board
							JavaSDM.ensure(!rowNode.equals(board));

							// check isomorphic binding between objects field and f2n
							JavaSDM.ensure(!field.equals(f2n));

							// check isomorphic binding between objects root and f2n
							JavaSDM.ensure(!root.equals(f2n));

							// check isomorphic binding between objects row and f2n
							JavaSDM.ensure(!row.equals(f2n));

							// check isomorphic binding between objects rowNode and f2n
							JavaSDM.ensure(!rowNode.equals(f2n));

							// check isomorphic binding between objects root and field
							JavaSDM.ensure(!root.equals(field));

							// check isomorphic binding between objects row and field
							JavaSDM.ensure(!row.equals(field));

							// check isomorphic binding between objects rowNode and field
							JavaSDM.ensure(!rowNode.equals(field));

							// check isomorphic binding between objects row and root
							JavaSDM.ensure(!row.equals(root));

							// check isomorphic binding between objects rowNode and root
							JavaSDM.ensure(!rowNode.equals(root));

							// check isomorphic binding between objects rowNode and row
							JavaSDM.ensure(!rowNode.equals(row));

							// create object f2n__source__row
							f2n__source__row = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object f2n__target__field
							f2n__target__field = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object field__children__rowNode
							field__children__rowNode = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object root__children__rowNode
							root__children__rowNode = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object row__board__board
							row__board__board = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// assign attribute row__board__board
							row__board__board.setName("board");
							// assign attribute f2n__source__row
							f2n__source__row.setName("f2n__source__row");
							// assign attribute f2n__target__field
							f2n__target__field.setName("f2n__target__field");
							// assign attribute field__children__rowNode
							field__children__rowNode
									.setName("field__children__rowNode");
							// assign attribute root__children__rowNode
							root__children__rowNode
									.setName("root__children__rowNode");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											f2n__source__row, "createdEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											f2n__target__field, "createdEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											field__children__rowNode,
											"createdEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											root__children__rowNode,
											"createdEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											row__board__board,
											"translatedEdges");
							// create link
							f2n__source__row.setTrg(row);

							// create link
							row__board__board.setSrc(row);

							// create link
							field__children__rowNode.setTrg(rowNode);

							// create link
							root__children__rowNode.setTrg(rowNode);

							// create link
							f2n__source__row.setSrc(f2n);

							// create link
							f2n__target__field.setSrc(f2n);

							// create link
							row__board__board.setTrg(board);

							// create link
							f2n__target__field.setTrg(field);

							// create link
							field__children__rowNode.setSrc(field);

							// create link
							root__children__rowNode.setSrc(root);

							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						return ruleResult;

					}

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IsAppropriateRuleResult isAppropriate_FWD_Field_0(Field row) {
		boolean fujaba__Success = false;
		Object _TmpObject = null;
		EClass eClass = null;
		Iterator fujaba__IterEClassToPerformOperation = null;
		EOperation performOperation = null;
		IsAppropriateRuleResult ruleResult = null;
		Match match = null;
		Edge row__board__null = null;
		Board board = null;
		Iterator fujaba__IterRuleResultToMatch = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			_TmpObject = (this.eClass());

			// ensure correct type and really bound of object eClass
			JavaSDM.ensure(_TmpObject instanceof EClass);
			eClass = (EClass) _TmpObject;

			// iterate to-many link eOperations from eClass to performOperation
			fujaba__Success = false;

			fujaba__IterEClassToPerformOperation = eClass.getEOperations()
					.iterator();

			while (!(fujaba__Success)
					&& fujaba__IterEClassToPerformOperation.hasNext()) {
				try {
					performOperation = (EOperation) fujaba__IterEClassToPerformOperation
							.next();

					// check object performOperation is really bound
					JavaSDM.ensure(performOperation != null);
					// attribute condition
					JavaSDM.ensure(JavaSDM.stringCompare(
							performOperation.getName(), "perform_FWD_Field_0") == 0);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE
					.createIsAppropriateRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			// create link
			ruleResult.setPerformOperation(performOperation);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern test core match
		try {
			fujaba__Success = false;

			// check object row is really bound
			JavaSDM.ensure(row != null);
			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// bind object
			board = row.getBoard();

			// check object board is really bound
			JavaSDM.ensure(board != null);

			// create object match
			match = TGGRuntimeFactory.eINSTANCE.createMatch();
			// create link
			ruleResult.getMatches().add(match);

			// story pattern collect elements to be translated
			try {
				fujaba__Success = false;

				// check object board is really bound
				JavaSDM.ensure(board != null);
				// check object match is really bound
				JavaSDM.ensure(match != null);
				// check object row is really bound
				JavaSDM.ensure(row != null);
				// create object row__board__null
				row__board__null = TGGRuntimeFactory.eINSTANCE.createEdge();
				// assign attribute row__board__null
				row__board__null.setName("board");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match, row,
						"toBeTranslatedElements");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						row__board__null, "toBeTranslatedEdges");
				// create link
				row__board__null.setSrc(row);

				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(
						row__board__null, board, "trg");
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			// story pattern collect context nodes
			try {
				fujaba__Success = false;

				// check object board is really bound
				JavaSDM.ensure(board != null);
				// check object match is really bound
				JavaSDM.ensure(match != null);
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						board, "contextElements");
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern set success
		try {
			fujaba__Success = false;

			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link matches from ruleResult to match
			fujaba__Success = false;

			fujaba__IterRuleResultToMatch = ruleResult.getMatches().iterator();

			while (!(fujaba__Success)
					&& fujaba__IterRuleResultToMatch.hasNext()) {
				try {
					match = (Match) fujaba__IterRuleResultToMatch.next();

					// check object match is really bound
					JavaSDM.ensure(match != null);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// assign attribute ruleResult
			ruleResult.setSuccess(true);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PerformRuleResult perform_BWD_Node_1(Node rowNode) {
		boolean fujaba__Success = false;
		PerformRuleResult ruleResult = null;
		Field row = null;
		FieldToNode f2n = null;
		Edge f2n__source__row = null;
		Edge row__board__board = null;
		Edge field__children__rowNode = null;
		Edge root__children__rowNode = null;
		Edge f2n__target__field = null;
		Board board = null;
		Iterator fujaba__IterRootToB2n = null;
		BoardToNode b2n = null;
		Node root = null;
		Node field = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE.createPerformRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern find context
		try {
			fujaba__Success = false;

			// check object rowNode is really bound
			JavaSDM.ensure(rowNode != null);
			// bind object
			field = rowNode.getParentNode();

			// check object field is really bound
			JavaSDM.ensure(field != null);

			// check isomorphic binding between objects rowNode and field
			JavaSDM.ensure(!rowNode.equals(field));

			// bind object
			root = rowNode.getParentNode();

			// check object root is really bound
			JavaSDM.ensure(root != null);

			// check isomorphic binding between objects root and field
			JavaSDM.ensure(!root.equals(field));

			// check isomorphic binding between objects rowNode and root
			JavaSDM.ensure(!rowNode.equals(root));

			// iterate to-many link target from root to b2n
			fujaba__Success = false;

			fujaba__IterRootToB2n = new ArrayList(
					org.moflon.util.eMoflonEMFUtil.getOppositeReference(root,
							BoardToNode.class, "target")).iterator();

			while (fujaba__IterRootToB2n.hasNext()) {
				try {
					b2n = (BoardToNode) fujaba__IterRootToB2n.next();

					// check object b2n is really bound
					JavaSDM.ensure(b2n != null);
					// bind object
					board = b2n.getSource();

					// check object board is really bound
					JavaSDM.ensure(board != null);

					// Create CSP
					CSP csp = CspFactory.eINSTANCE.createCSP();

					// Create literals
					Variable<Integer> literal0 = CspFactory.eINSTANCE
							.createVariable("literal0", true, csp);
					literal0.setValue(0);

					// Create implicit parameters
					Variable<Integer> var_rowNode_index = CspFactory.eINSTANCE
							.createVariable("rowNode.index", true, csp);
					var_rowNode_index.setValue(rowNode.getIndex());
					Variable<Integer> var_field_index = CspFactory.eINSTANCE
							.createVariable("field.index", true, csp);
					var_field_index.setValue(field.getIndex());

					// Create explicit parameters

					// Create unbound variables
					Variable<Integer> var_row_y = CspFactory.eINSTANCE
							.createVariable("row.y", csp);
					Variable<Integer> var_row_x = CspFactory.eINSTANCE
							.createVariable("row.x", csp);

					// Create constraints
					Eq<Integer> eq = new Eq<Integer>();
					Eq<Integer> eq_0 = new Eq<Integer>();
					Eq<Integer> eq_1 = new Eq<Integer>();

					csp.getConstraints().add(eq);
					csp.getConstraints().add(eq_0);
					csp.getConstraints().add(eq_1);

					// Solve CSP
					eq.solve(var_row_y, var_rowNode_index);
					eq_0.solve(var_row_x, var_field_index);
					eq_1.solve(var_row_x, literal0);

					fujaba__Success = csp.check();
					if (fujaba__Success) {
						// story pattern perform transformation
						try {
							fujaba__Success = false;

							// check object b2n is really bound
							JavaSDM.ensure(b2n != null);
							// check object board is really bound
							JavaSDM.ensure(board != null);
							// check object field is really bound
							JavaSDM.ensure(field != null);
							// check object root is really bound
							JavaSDM.ensure(root != null);
							// check object rowNode is really bound
							JavaSDM.ensure(rowNode != null);
							// check isomorphic binding between objects root and field
							JavaSDM.ensure(!root.equals(field));

							// check isomorphic binding between objects rowNode and field
							JavaSDM.ensure(!rowNode.equals(field));

							// check isomorphic binding between objects rowNode and root
							JavaSDM.ensure(!rowNode.equals(root));

							// check link children from rowNode to field
							JavaSDM.ensure(field.equals(rowNode.getParentNode()));

							// check link children from rowNode to root
							JavaSDM.ensure(root.equals(rowNode.getParentNode()));

							// check link source from b2n to board
							JavaSDM.ensure(board.equals(b2n.getSource()));

							// check link target from b2n to root
							JavaSDM.ensure(root.equals(b2n.getTarget()));

							// create object row
							row = BoardGameFactory.eINSTANCE.createField();
							// create object f2n
							f2n = BoardGameToTreeIntegrationFactory.eINSTANCE
									.createFieldToNode();
							// assign attribute row
							row.setY(var_row_y.getValue());
							// assign attribute row
							row.setX(var_row_x.getValue());
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(f2n, field, "target");
							// create link
							f2n.setSource(row);

							// create link
							board.getFields().add(row);

							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						// story pattern collect translated elements
						try {
							fujaba__Success = false;

							// check object f2n is really bound
							JavaSDM.ensure(f2n != null);
							// check object field is really bound
							JavaSDM.ensure(field != null);
							// check object row is really bound
							JavaSDM.ensure(row != null);
							// check object rowNode is really bound
							JavaSDM.ensure(rowNode != null);
							// check object ruleResult is really bound
							JavaSDM.ensure(ruleResult != null);
							// check isomorphic binding between objects rowNode and field
							JavaSDM.ensure(!rowNode.equals(field));

							// assign attribute ruleResult
							ruleResult.setSuccess(true);
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, rowNode,
											"translatedElements");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, row,
											"createdElements");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, field,
											"translatedElements");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult, f2n,
											"createdLinkElements");
							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						// story pattern bookkeeping for edges
						try {
							fujaba__Success = false;

							// check object b2n is really bound
							JavaSDM.ensure(b2n != null);
							// check object board is really bound
							JavaSDM.ensure(board != null);
							// check object f2n is really bound
							JavaSDM.ensure(f2n != null);
							// check object field is really bound
							JavaSDM.ensure(field != null);
							// check object root is really bound
							JavaSDM.ensure(root != null);
							// check object row is really bound
							JavaSDM.ensure(row != null);
							// check object rowNode is really bound
							JavaSDM.ensure(rowNode != null);
							// check object ruleResult is really bound
							JavaSDM.ensure(ruleResult != null);
							// check isomorphic binding between objects board and b2n
							JavaSDM.ensure(!board.equals(b2n));

							// check isomorphic binding between objects f2n and b2n
							JavaSDM.ensure(!f2n.equals(b2n));

							// check isomorphic binding between objects field and b2n
							JavaSDM.ensure(!field.equals(b2n));

							// check isomorphic binding between objects root and b2n
							JavaSDM.ensure(!root.equals(b2n));

							// check isomorphic binding between objects row and b2n
							JavaSDM.ensure(!row.equals(b2n));

							// check isomorphic binding between objects rowNode and b2n
							JavaSDM.ensure(!rowNode.equals(b2n));

							// check isomorphic binding between objects f2n and board
							JavaSDM.ensure(!f2n.equals(board));

							// check isomorphic binding between objects field and board
							JavaSDM.ensure(!field.equals(board));

							// check isomorphic binding between objects root and board
							JavaSDM.ensure(!root.equals(board));

							// check isomorphic binding between objects row and board
							JavaSDM.ensure(!row.equals(board));

							// check isomorphic binding between objects rowNode and board
							JavaSDM.ensure(!rowNode.equals(board));

							// check isomorphic binding between objects field and f2n
							JavaSDM.ensure(!field.equals(f2n));

							// check isomorphic binding between objects root and f2n
							JavaSDM.ensure(!root.equals(f2n));

							// check isomorphic binding between objects row and f2n
							JavaSDM.ensure(!row.equals(f2n));

							// check isomorphic binding between objects rowNode and f2n
							JavaSDM.ensure(!rowNode.equals(f2n));

							// check isomorphic binding between objects root and field
							JavaSDM.ensure(!root.equals(field));

							// check isomorphic binding between objects row and field
							JavaSDM.ensure(!row.equals(field));

							// check isomorphic binding between objects rowNode and field
							JavaSDM.ensure(!rowNode.equals(field));

							// check isomorphic binding between objects row and root
							JavaSDM.ensure(!row.equals(root));

							// check isomorphic binding between objects rowNode and root
							JavaSDM.ensure(!rowNode.equals(root));

							// check isomorphic binding between objects rowNode and row
							JavaSDM.ensure(!rowNode.equals(row));

							// create object f2n__source__row
							f2n__source__row = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object row__board__board
							row__board__board = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object field__children__rowNode
							field__children__rowNode = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object root__children__rowNode
							root__children__rowNode = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// create object f2n__target__field
							f2n__target__field = TGGRuntimeFactory.eINSTANCE
									.createEdge();
							// assign attribute row__board__board
							row__board__board.setName("row__board__board");
							// assign attribute f2n__source__row
							f2n__source__row.setName("f2n__source__row");
							// assign attribute f2n__target__field
							f2n__target__field.setName("f2n__target__field");
							// assign attribute field__children__rowNode
							field__children__rowNode.setName("children");
							// assign attribute root__children__rowNode
							root__children__rowNode.setName("children");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											f2n__source__row, "createdEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											row__board__board, "createdEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											field__children__rowNode,
											"translatedEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											root__children__rowNode,
											"translatedEdges");
							// create link
							org.moflon.util.eMoflonEMFUtil
									.addOppositeReference(ruleResult,
											f2n__target__field, "createdEdges");
							// create link
							f2n__source__row.setTrg(row);

							// create link
							row__board__board.setSrc(row);

							// create link
							field__children__rowNode.setTrg(rowNode);

							// create link
							root__children__rowNode.setTrg(rowNode);

							// create link
							f2n__target__field.setSrc(f2n);

							// create link
							f2n__source__row.setSrc(f2n);

							// create link
							row__board__board.setTrg(board);

							// create link
							field__children__rowNode.setSrc(field);

							// create link
							f2n__target__field.setTrg(field);

							// create link
							root__children__rowNode.setSrc(root);

							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}

						return ruleResult;

					}

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IsAppropriateRuleResult isAppropriate_BWD_Node_1(Node rowNode) {
		boolean fujaba__Success = false;
		Object _TmpObject = null;
		EClass eClass = null;
		Iterator fujaba__IterEClassToPerformOperation = null;
		EOperation performOperation = null;
		IsAppropriateRuleResult ruleResult = null;
		Match match = null;
		Edge field__children__rowNode = null;
		Edge null__children__rowNode = null;
		Node root = null;
		Node field = null;
		Iterator fujaba__IterRuleResultToMatch = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			_TmpObject = (this.eClass());

			// ensure correct type and really bound of object eClass
			JavaSDM.ensure(_TmpObject instanceof EClass);
			eClass = (EClass) _TmpObject;

			// iterate to-many link eOperations from eClass to performOperation
			fujaba__Success = false;

			fujaba__IterEClassToPerformOperation = eClass.getEOperations()
					.iterator();

			while (!(fujaba__Success)
					&& fujaba__IterEClassToPerformOperation.hasNext()) {
				try {
					performOperation = (EOperation) fujaba__IterEClassToPerformOperation
							.next();

					// check object performOperation is really bound
					JavaSDM.ensure(performOperation != null);
					// attribute condition
					JavaSDM.ensure(JavaSDM.stringCompare(
							performOperation.getName(), "perform_BWD_Node_1") == 0);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE
					.createIsAppropriateRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			// create link
			ruleResult.setPerformOperation(performOperation);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern test core match
		try {
			fujaba__Success = false;

			// check object rowNode is really bound
			JavaSDM.ensure(rowNode != null);
			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// bind object
			field = rowNode.getParentNode();

			// check object field is really bound
			JavaSDM.ensure(field != null);

			// check isomorphic binding between objects rowNode and field
			JavaSDM.ensure(!rowNode.equals(field));

			// bind object
			root = rowNode.getParentNode();

			// check object root is really bound
			JavaSDM.ensure(root != null);

			// check isomorphic binding between objects root and field
			JavaSDM.ensure(!root.equals(field));

			// check isomorphic binding between objects rowNode and root
			JavaSDM.ensure(!rowNode.equals(root));

			// create object match
			match = TGGRuntimeFactory.eINSTANCE.createMatch();
			// create link
			ruleResult.getMatches().add(match);

			// story pattern collect elements to be translated
			try {
				fujaba__Success = false;

				// check object field is really bound
				JavaSDM.ensure(field != null);
				// check object match is really bound
				JavaSDM.ensure(match != null);
				// check object root is really bound
				JavaSDM.ensure(root != null);
				// check object rowNode is really bound
				JavaSDM.ensure(rowNode != null);
				// check isomorphic binding between objects root and field
				JavaSDM.ensure(!root.equals(field));

				// check isomorphic binding between objects rowNode and field
				JavaSDM.ensure(!rowNode.equals(field));

				// check isomorphic binding between objects rowNode and root
				JavaSDM.ensure(!rowNode.equals(root));

				// create object field__children__rowNode
				field__children__rowNode = TGGRuntimeFactory.eINSTANCE
						.createEdge();
				// create object null__children__rowNode
				null__children__rowNode = TGGRuntimeFactory.eINSTANCE
						.createEdge();
				// assign attribute field__children__rowNode
				field__children__rowNode.setName("children");
				// assign attribute null__children__rowNode
				null__children__rowNode.setName("children");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						field__children__rowNode, "toBeTranslatedEdges");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						null__children__rowNode, "toBeTranslatedEdges");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						rowNode, "toBeTranslatedElements");
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						field, "toBeTranslatedElements");
				// create link
				null__children__rowNode.setTrg(rowNode);

				// create link
				field__children__rowNode.setTrg(rowNode);

				// create link
				field__children__rowNode.setSrc(field);

				// create link
				null__children__rowNode.setSrc(root);

				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			// story pattern collect context nodes
			try {
				fujaba__Success = false;

				// check object match is really bound
				JavaSDM.ensure(match != null);
				// check object root is really bound
				JavaSDM.ensure(root != null);
				// create link
				org.moflon.util.eMoflonEMFUtil.addOppositeReference(match,
						root, "contextElements");
				fujaba__Success = true;
			} catch (JavaSDMException fujaba__InternalException) {
				fujaba__Success = false;
			}

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern set success
		try {
			fujaba__Success = false;

			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link matches from ruleResult to match
			fujaba__Success = false;

			fujaba__IterRuleResultToMatch = ruleResult.getMatches().iterator();

			while (!(fujaba__Success)
					&& fujaba__IterRuleResultToMatch.hasNext()) {
				try {
					match = (Match) fujaba__IterRuleResultToMatch.next();

					// check object match is really bound
					JavaSDM.ensure(match != null);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// assign attribute ruleResult
			ruleResult.setSuccess(true);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PerformRuleResult perform_BWD_Node_2(Node field) {
		boolean fujaba__Success = false;
		PerformRuleResult ruleResult = null;
		Field row = null;
		FieldToNode f2n = null;
		Edge f2n__source__row = null;
		Edge root__children__rowNode = null;
		Edge f2n__target__field = null;
		Edge row__board__board = null;
		Edge field__children__rowNode = null;
		Board board = null;
		Iterator fujaba__IterRootToB2n = null;
		BoardToNode b2n = null;
		Node root = null;
		Iterator fujaba__IterFieldToRowNode = null;
		Object _TmpObject = null;
		Node rowNode = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE.createPerformRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern find context
		try {
			fujaba__Success = false;

			// check object field is really bound
			JavaSDM.ensure(field != null);
			// iterate to-many link children from field to rowNode
			fujaba__Success = false;

			fujaba__IterFieldToRowNode = new ArrayList(field.getChildren())
					.iterator();

			while (fujaba__IterFieldToRowNode.hasNext()) {
				try {
					_TmpObject = fujaba__IterFieldToRowNode.next();

					// ensure correct type and really bound of object rowNode
					JavaSDM.ensure(_TmpObject instanceof Node);
					rowNode = (Node) _TmpObject;

					// check isomorphic binding between objects rowNode and field
					JavaSDM.ensure(!rowNode.equals(field));

					// bind object
					root = rowNode.getParentNode();

					// check object root is really bound
					JavaSDM.ensure(root != null);

					// check isomorphic binding between objects root and field
					JavaSDM.ensure(!root.equals(field));

					// check isomorphic binding between objects rowNode and root
					JavaSDM.ensure(!rowNode.equals(root));

					// iterate to-many link target from root to b2n
					fujaba__Success = false;

					fujaba__IterRootToB2n = new ArrayList(
							org.moflon.util.eMoflonEMFUtil
									.getOppositeReference(root,
											BoardToNode.class, "target"))
							.iterator();

					while (fujaba__IterRootToB2n.hasNext()) {
						try {
							b2n = (BoardToNode) fujaba__IterRootToB2n.next();

							// check object b2n is really bound
							JavaSDM.ensure(b2n != null);
							// bind object
							board = b2n.getSource();

							// check object board is really bound
							JavaSDM.ensure(board != null);

							// Create CSP
							CSP csp = CspFactory.eINSTANCE.createCSP();

							// Create literals
							Variable<Integer> literal0 = CspFactory.eINSTANCE
									.createVariable("literal0", true, csp);
							literal0.setValue(0);

							// Create implicit parameters
							Variable<Integer> var_rowNode_index = CspFactory.eINSTANCE
									.createVariable("rowNode.index", true, csp);
							var_rowNode_index.setValue(rowNode.getIndex());
							Variable<Integer> var_field_index = CspFactory.eINSTANCE
									.createVariable("field.index", true, csp);
							var_field_index.setValue(field.getIndex());

							// Create explicit parameters

							// Create unbound variables
							Variable<Integer> var_row_y = CspFactory.eINSTANCE
									.createVariable("row.y", csp);
							Variable<Integer> var_row_x = CspFactory.eINSTANCE
									.createVariable("row.x", csp);

							// Create constraints
							Eq<Integer> eq = new Eq<Integer>();
							Eq<Integer> eq_0 = new Eq<Integer>();
							Eq<Integer> eq_1 = new Eq<Integer>();

							csp.getConstraints().add(eq);
							csp.getConstraints().add(eq_0);
							csp.getConstraints().add(eq_1);

							// Solve CSP
							eq.solve(var_row_y, var_rowNode_index);
							eq_0.solve(var_row_x, var_field_index);
							eq_1.solve(var_row_x, literal0);

							fujaba__Success = csp.check();
							if (fujaba__Success) {
								// story pattern perform transformation
								try {
									fujaba__Success = false;

									// check object b2n is really bound
									JavaSDM.ensure(b2n != null);
									// check object board is really bound
									JavaSDM.ensure(board != null);
									// check object field is really bound
									JavaSDM.ensure(field != null);
									// check object root is really bound
									JavaSDM.ensure(root != null);
									// check object rowNode is really bound
									JavaSDM.ensure(rowNode != null);
									// check isomorphic binding between objects root and field
									JavaSDM.ensure(!root.equals(field));

									// check isomorphic binding between objects rowNode and field
									JavaSDM.ensure(!rowNode.equals(field));

									// check isomorphic binding between objects rowNode and root
									JavaSDM.ensure(!rowNode.equals(root));

									// check link children from rowNode to field
									JavaSDM.ensure(field.equals(rowNode
											.getParentNode()));

									// check link children from rowNode to root
									JavaSDM.ensure(root.equals(rowNode
											.getParentNode()));

									// check link source from b2n to board
									JavaSDM.ensure(board.equals(b2n.getSource()));

									// check link target from b2n to root
									JavaSDM.ensure(root.equals(b2n.getTarget()));

									// create object row
									row = BoardGameFactory.eINSTANCE
											.createField();
									// create object f2n
									f2n = BoardGameToTreeIntegrationFactory.eINSTANCE
											.createFieldToNode();
									// assign attribute row
									row.setY(var_row_y.getValue());
									// assign attribute row
									row.setX(var_row_x.getValue());
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(f2n, field,
													"target");
									// create link
									f2n.setSource(row);

									// create link
									board.getFields().add(row);

									fujaba__Success = true;
								} catch (JavaSDMException fujaba__InternalException) {
									fujaba__Success = false;
								}

								// story pattern collect translated elements
								try {
									fujaba__Success = false;

									// check object f2n is really bound
									JavaSDM.ensure(f2n != null);
									// check object field is really bound
									JavaSDM.ensure(field != null);
									// check object row is really bound
									JavaSDM.ensure(row != null);
									// check object rowNode is really bound
									JavaSDM.ensure(rowNode != null);
									// check object ruleResult is really bound
									JavaSDM.ensure(ruleResult != null);
									// check isomorphic binding between objects rowNode and field
									JavaSDM.ensure(!rowNode.equals(field));

									// assign attribute ruleResult
									ruleResult.setSuccess(true);
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													row, "createdElements");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													field, "translatedElements");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													rowNode,
													"translatedElements");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													f2n, "createdLinkElements");
									fujaba__Success = true;
								} catch (JavaSDMException fujaba__InternalException) {
									fujaba__Success = false;
								}

								// story pattern bookkeeping for edges
								try {
									fujaba__Success = false;

									// check object b2n is really bound
									JavaSDM.ensure(b2n != null);
									// check object board is really bound
									JavaSDM.ensure(board != null);
									// check object f2n is really bound
									JavaSDM.ensure(f2n != null);
									// check object field is really bound
									JavaSDM.ensure(field != null);
									// check object root is really bound
									JavaSDM.ensure(root != null);
									// check object row is really bound
									JavaSDM.ensure(row != null);
									// check object rowNode is really bound
									JavaSDM.ensure(rowNode != null);
									// check object ruleResult is really bound
									JavaSDM.ensure(ruleResult != null);
									// check isomorphic binding between objects board and b2n
									JavaSDM.ensure(!board.equals(b2n));

									// check isomorphic binding between objects f2n and b2n
									JavaSDM.ensure(!f2n.equals(b2n));

									// check isomorphic binding between objects field and b2n
									JavaSDM.ensure(!field.equals(b2n));

									// check isomorphic binding between objects root and b2n
									JavaSDM.ensure(!root.equals(b2n));

									// check isomorphic binding between objects row and b2n
									JavaSDM.ensure(!row.equals(b2n));

									// check isomorphic binding between objects rowNode and b2n
									JavaSDM.ensure(!rowNode.equals(b2n));

									// check isomorphic binding between objects f2n and board
									JavaSDM.ensure(!f2n.equals(board));

									// check isomorphic binding between objects field and board
									JavaSDM.ensure(!field.equals(board));

									// check isomorphic binding between objects root and board
									JavaSDM.ensure(!root.equals(board));

									// check isomorphic binding between objects row and board
									JavaSDM.ensure(!row.equals(board));

									// check isomorphic binding between objects rowNode and board
									JavaSDM.ensure(!rowNode.equals(board));

									// check isomorphic binding between objects field and f2n
									JavaSDM.ensure(!field.equals(f2n));

									// check isomorphic binding between objects root and f2n
									JavaSDM.ensure(!root.equals(f2n));

									// check isomorphic binding between objects row and f2n
									JavaSDM.ensure(!row.equals(f2n));

									// check isomorphic binding between objects rowNode and f2n
									JavaSDM.ensure(!rowNode.equals(f2n));

									// check isomorphic binding between objects root and field
									JavaSDM.ensure(!root.equals(field));

									// check isomorphic binding between objects row and field
									JavaSDM.ensure(!row.equals(field));

									// check isomorphic binding between objects rowNode and field
									JavaSDM.ensure(!rowNode.equals(field));

									// check isomorphic binding between objects row and root
									JavaSDM.ensure(!row.equals(root));

									// check isomorphic binding between objects rowNode and root
									JavaSDM.ensure(!rowNode.equals(root));

									// check isomorphic binding between objects rowNode and row
									JavaSDM.ensure(!rowNode.equals(row));

									// create object f2n__source__row
									f2n__source__row = TGGRuntimeFactory.eINSTANCE
											.createEdge();
									// create object root__children__rowNode
									root__children__rowNode = TGGRuntimeFactory.eINSTANCE
											.createEdge();
									// create object f2n__target__field
									f2n__target__field = TGGRuntimeFactory.eINSTANCE
											.createEdge();
									// create object row__board__board
									row__board__board = TGGRuntimeFactory.eINSTANCE
											.createEdge();
									// create object field__children__rowNode
									field__children__rowNode = TGGRuntimeFactory.eINSTANCE
											.createEdge();
									// assign attribute row__board__board
									row__board__board
											.setName("row__board__board");
									// assign attribute f2n__source__row
									f2n__source__row
											.setName("f2n__source__row");
									// assign attribute f2n__target__field
									f2n__target__field
											.setName("f2n__target__field");
									// assign attribute field__children__rowNode
									field__children__rowNode
											.setName("children");
									// assign attribute root__children__rowNode
									root__children__rowNode.setName("children");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													f2n__source__row,
													"createdEdges");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													root__children__rowNode,
													"translatedEdges");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													f2n__target__field,
													"createdEdges");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													row__board__board,
													"createdEdges");
									// create link
									org.moflon.util.eMoflonEMFUtil
											.addOppositeReference(ruleResult,
													field__children__rowNode,
													"translatedEdges");
									// create link
									f2n__source__row.setTrg(row);

									// create link
									row__board__board.setSrc(row);

									// create link
									field__children__rowNode.setTrg(rowNode);

									// create link
									root__children__rowNode.setTrg(rowNode);

									// create link
									f2n__source__row.setSrc(f2n);

									// create link
									f2n__target__field.setSrc(f2n);

									// create link
									row__board__board.setTrg(board);

									// create link
									f2n__target__field.setTrg(field);

									// create link
									field__children__rowNode.setSrc(field);

									// create link
									root__children__rowNode.setSrc(root);

									fujaba__Success = true;
								} catch (JavaSDMException fujaba__InternalException) {
									fujaba__Success = false;
								}

								return ruleResult;

							}

							fujaba__Success = true;
						} catch (JavaSDMException fujaba__InternalException) {
							fujaba__Success = false;
						}
					}
					JavaSDM.ensure(fujaba__Success);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IsAppropriateRuleResult isAppropriate_BWD_Node_2(Node field) {
		boolean fujaba__Success = false;
		Object _TmpObject = null;
		EClass eClass = null;
		Iterator fujaba__IterEClassToPerformOperation = null;
		EOperation performOperation = null;
		IsAppropriateRuleResult ruleResult = null;
		Match match = null;
		Edge field__children__rowNode = null;
		Edge null__children__rowNode = null;
		Node root = null;
		Iterator fujaba__IterFieldToRowNode = null;
		Node rowNode = null;
		Iterator fujaba__IterRuleResultToMatch = null;

		// story pattern prepare return value
		try {
			fujaba__Success = false;

			_TmpObject = (this.eClass());

			// ensure correct type and really bound of object eClass
			JavaSDM.ensure(_TmpObject instanceof EClass);
			eClass = (EClass) _TmpObject;

			// iterate to-many link eOperations from eClass to performOperation
			fujaba__Success = false;

			fujaba__IterEClassToPerformOperation = eClass.getEOperations()
					.iterator();

			while (!(fujaba__Success)
					&& fujaba__IterEClassToPerformOperation.hasNext()) {
				try {
					performOperation = (EOperation) fujaba__IterEClassToPerformOperation
							.next();

					// check object performOperation is really bound
					JavaSDM.ensure(performOperation != null);
					// attribute condition
					JavaSDM.ensure(JavaSDM.stringCompare(
							performOperation.getName(), "perform_BWD_Node_2") == 0);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// create object ruleResult
			ruleResult = TGGRuntimeFactory.eINSTANCE
					.createIsAppropriateRuleResult();
			// assign attribute ruleResult
			ruleResult.setSuccess(false);
			// create link
			ruleResult.setPerformOperation(performOperation);

			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern test core match
		try {
			fujaba__Success = false;

			// check object field is really bound
			JavaSDM.ensure(field != null);
			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link children from field to rowNode
			fujaba__Success = false;

			fujaba__IterFieldToRowNode = new ArrayList(field.getChildren())
					.iterator();

			while (fujaba__IterFieldToRowNode.hasNext()) {
				try {
					_TmpObject = fujaba__IterFieldToRowNode.next();

					// ensure correct type and really bound of object rowNode
					JavaSDM.ensure(_TmpObject instanceof Node);
					rowNode = (Node) _TmpObject;

					// check isomorphic binding between objects rowNode and field
					JavaSDM.ensure(!rowNode.equals(field));

					// bind object
					root = rowNode.getParentNode();

					// check object root is really bound
					JavaSDM.ensure(root != null);

					// check isomorphic binding between objects root and field
					JavaSDM.ensure(!root.equals(field));

					// check isomorphic binding between objects rowNode and root
					JavaSDM.ensure(!rowNode.equals(root));

					// create object match
					match = TGGRuntimeFactory.eINSTANCE.createMatch();
					// create link
					ruleResult.getMatches().add(match);

					// story pattern collect elements to be translated
					try {
						fujaba__Success = false;

						// check object field is really bound
						JavaSDM.ensure(field != null);
						// check object match is really bound
						JavaSDM.ensure(match != null);
						// check object root is really bound
						JavaSDM.ensure(root != null);
						// check object rowNode is really bound
						JavaSDM.ensure(rowNode != null);
						// check isomorphic binding between objects root and field
						JavaSDM.ensure(!root.equals(field));

						// check isomorphic binding between objects rowNode and field
						JavaSDM.ensure(!rowNode.equals(field));

						// check isomorphic binding between objects rowNode and root
						JavaSDM.ensure(!rowNode.equals(root));

						// create object field__children__rowNode
						field__children__rowNode = TGGRuntimeFactory.eINSTANCE
								.createEdge();
						// create object null__children__rowNode
						null__children__rowNode = TGGRuntimeFactory.eINSTANCE
								.createEdge();
						// assign attribute field__children__rowNode
						field__children__rowNode.setName("children");
						// assign attribute null__children__rowNode
						null__children__rowNode.setName("children");
						// create link
						org.moflon.util.eMoflonEMFUtil.addOppositeReference(
								match, field__children__rowNode,
								"toBeTranslatedEdges");
						// create link
						org.moflon.util.eMoflonEMFUtil.addOppositeReference(
								match, rowNode, "toBeTranslatedElements");
						// create link
						org.moflon.util.eMoflonEMFUtil.addOppositeReference(
								match, field, "toBeTranslatedElements");
						// create link
						org.moflon.util.eMoflonEMFUtil.addOppositeReference(
								match, null__children__rowNode,
								"toBeTranslatedEdges");
						// create link
						field__children__rowNode.setTrg(rowNode);

						// create link
						null__children__rowNode.setTrg(rowNode);

						// create link
						field__children__rowNode.setSrc(field);

						// create link
						null__children__rowNode.setSrc(root);

						fujaba__Success = true;
					} catch (JavaSDMException fujaba__InternalException) {
						fujaba__Success = false;
					}

					// story pattern collect context nodes
					try {
						fujaba__Success = false;

						// check object match is really bound
						JavaSDM.ensure(match != null);
						// check object root is really bound
						JavaSDM.ensure(root != null);
						// create link
						org.moflon.util.eMoflonEMFUtil.addOppositeReference(
								match, root, "contextElements");
						fujaba__Success = true;
					} catch (JavaSDMException fujaba__InternalException) {
						fujaba__Success = false;
					}

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		// story pattern set success
		try {
			fujaba__Success = false;

			// check object ruleResult is really bound
			JavaSDM.ensure(ruleResult != null);
			// iterate to-many link matches from ruleResult to match
			fujaba__Success = false;

			fujaba__IterRuleResultToMatch = ruleResult.getMatches().iterator();

			while (!(fujaba__Success)
					&& fujaba__IterRuleResultToMatch.hasNext()) {
				try {
					match = (Match) fujaba__IterRuleResultToMatch.next();

					// check object match is really bound
					JavaSDM.ensure(match != null);

					fujaba__Success = true;
				} catch (JavaSDMException fujaba__InternalException) {
					fujaba__Success = false;
				}
			}
			JavaSDM.ensure(fujaba__Success);
			// assign attribute ruleResult
			ruleResult.setSuccess(true);
			fujaba__Success = true;
		} catch (JavaSDMException fujaba__InternalException) {
			fujaba__Success = false;
		}

		return ruleResult;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments)
			throws InvocationTargetException {
		switch (operationID) {
		case RulesPackage.FIELD_RULE___PERFORM_FWD_FIELD_0__FIELD:
			return perform_FWD_Field_0((Field) arguments.get(0));
		case RulesPackage.FIELD_RULE___IS_APPROPRIATE_FWD_FIELD_0__FIELD:
			return isAppropriate_FWD_Field_0((Field) arguments.get(0));
		case RulesPackage.FIELD_RULE___PERFORM_BWD_NODE_1__NODE:
			return perform_BWD_Node_1((Node) arguments.get(0));
		case RulesPackage.FIELD_RULE___IS_APPROPRIATE_BWD_NODE_1__NODE:
			return isAppropriate_BWD_Node_1((Node) arguments.get(0));
		case RulesPackage.FIELD_RULE___PERFORM_BWD_NODE_2__NODE:
			return perform_BWD_Node_2((Node) arguments.get(0));
		case RulesPackage.FIELD_RULE___IS_APPROPRIATE_BWD_NODE_2__NODE:
			return isAppropriate_BWD_Node_2((Node) arguments.get(0));
		}
		return super.eInvoke(operationID, arguments);
	}

} //FieldRuleImpl
